﻿namespace NovellSecurity
{
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using Sitecore;
  using Sitecore.Caching;
  using Sitecore.Configuration;
  using Sitecore.Diagnostics;
  public class NovellUserCache : CustomCache
  {
    /// <summary>
    /// Initializes a new instance of the <see cref="NovellUserCache"/> class.
    /// </summary>
    public NovellUserCache()
      : base("NovellUsersCache", StringUtil.ParseSizeString(Settings.GetSetting("Novell.Caching.UsersCacheSize")))
    {
    }

    /// <summary>
    /// Gets the user.
    /// </summary>
    /// <param name="userName">Name of the user.</param>
    /// <returns></returns>
    public NovellUser GetUser(string userName)
    {
      Assert.ArgumentNotNullOrEmpty(userName, "userName");
      return (NovellUser)base.GetObject(userName);
    }

    /// <summary>
    /// Adds the user.
    /// </summary>
    /// <param name="user">The user.</param>
    public void AddUser(NovellUser user)
    {
      Assert.ArgumentNotNull(user, "user");
      base.SetObject(user.UserName.ToLower(), user, StringUtil.ParseSizeString("1KB"));
    }
  }
}
